import QS from 'qs'
import store from '@/store/index';
import { axios_instance  } from './config'

export function reg (params) {
  return axios_instance.post('user/register', QS.stringify(params),  {
    params: {
      lang: store.getters.getLang == 'zh' ? 'zh-cn' : 'en-us'
    }
  })
}
export function login (params) {
  return axios_instance.post('user/login', QS.stringify(params),  {
    params: {
      lang: store.getters.getLang == 'zh' ? 'zh-cn' : 'en-us'
    }
  })
}
export function userInfo () {
  const state = store.state.userinfo
  console.log(state.token)
  return axios_instance.post('user/index', QS.stringify({
    token: state && state.token
  }), {
    params: {
      lang: store.getters.getLang == 'zh' ? 'zh-cn' : 'en-us'
    }
  })
}

export function userApply (data) {
  const state = store.state.userinfo
  const obj = Object.assign(data, {
    token: state && state.token
  })
  return axios_instance.post('userapply/add', QS.stringify(obj), {
    params: {
      lang: store.getters.getLang == 'zh' ? 'zh-cn' : 'en-us'
    }
  })
}

export function carAdd (data) {
  const state = store.state.userinfo
  const obj = Object.assign(data, {
    token: state && state.token
  })
  return axios_instance.post('cmsmotorcade/add', QS.stringify(obj), {
    params: {
      lang: store.getters.getLang == 'zh' ? 'zh-cn' : 'en-us'
    }
  })
}

export function carList (data) {
  const state = store.state.userinfo
  const obj = Object.assign(data, {
    token: state && state.token
  })
  return axios_instance.post('cmsmotorcade/search', QS.stringify(obj), {
    params: {
      lang: store.getters.getLang == 'zh' ? 'zh-cn' : 'en-us'
    }
  })
}

//我的车队列表
export function mycmsmotorcade (data) {
  const state = store.state.userinfo
  const obj = Object.assign(data, {
    token: state && state.token
  })
  return axios_instance.post('cmsmotorcade/mycmsmotorcade', QS.stringify(obj), {
    params: {
      lang: store.getters.getLang == 'zh' ? 'zh-cn' : 'en-us'
    }
  })
}

//加入车队
export function applay (data) {
  const state = store.state.userinfo
  const obj = Object.assign(data, {
    token: state && state.token
  })
  return axios_instance.post('cmsmotorcade/applay', QS.stringify(obj), {
    params: {
      lang: store.getters.getLang == 'zh' ? 'zh-cn' : 'en-us'
    }
  })
}



export function cmsmessagelist (data) {
  const state = store.state.userinfo
  const obj = Object.assign(data, {
    token: state && state.token
  })
  return axios_instance.post('cmsmotorcade/cmsmessagelist', QS.stringify(obj), {
    params: {
      lang: store.getters.getLang == 'zh' ? 'zh-cn' : 'en-us'
    }
  })
}

export function cmsuploadfilesave (data) {
  const state = store.state.userinfo
  const obj = Object.assign(data, {
    token: state && state.token
  })
  return axios_instance.post('cmsmotorcade/cmsuploadfilesave', QS.stringify(obj), {
    params: {
      lang: store.getters.getLang == 'zh' ? 'zh-cn' : 'en-us'
    }
  })
}

//我得文件列表
export function cmsuploadfilelist (data) {
  const state = store.state.userinfo
  const obj = Object.assign(data, {
    token: state && state.token
  })
  return axios_instance.post('cmsmotorcade/cmsuploadfilelist', QS.stringify(obj), {
    params: {
      lang: store.getters.getLang == 'zh' ? 'zh-cn' : 'en-us'
    }
  })
}

//查询车队信息
export function getcmsmotorcadeinfo (data) {
  const state = store.state.userinfo
  const obj = Object.assign(data, {
    token: state && state.token
  })
  return axios_instance.post('cmsmotorcade/getcmsmotorcadeinfo', QS.stringify(obj), {
    params: {
      lang: store.getters.getLang == 'zh' ? 'zh-cn' : 'en-us'
    }
  })
}

//车队队员列表
export function cmsmotorcadepeolist (data) {
  const state = store.state.userinfo
  const obj = Object.assign(data, {
    token: state && state.token
  })
  return axios_instance.post('cmsmotorcade/cmsmotorcadepeolist', QS.stringify(obj), {
    params: {
      lang: store.getters.getLang == 'zh' ? 'zh-cn' : 'en-us'
    }
  })
}

//设置角色
export function setroletype (data) {
  const state = store.state.userinfo
  const obj = Object.assign(data, {
    token: state && state.token
  })
  return axios_instance.post('cmsmotorcade/setroletype', QS.stringify(obj), {
    params: {
      lang: store.getters.getLang == 'zh' ? 'zh-cn' : 'en-us'
    }
  })
}